package 
{
    import com.bit101.components.Label;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Vector3D;
    import mge.particles.Descriptor;
    import mge.particles.ParticleSystem;
    import mge.Timer;
    
	/**
	 * ...
	 * @author ivan
	 */   
	public class Main extends Sprite 
	{
    [Embed(source="C:/lib/mge/projects/particle_editor/resources/particles.png")]
    private var rParticles:Class;

		public function Main():void  
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
        
		private function init(e:Event = null):void 
		{
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;

      removeEventListener(Event.ADDED_TO_STAGE, init);
      stage.frameRate = 60;

      // entry point

      this.addEventListener(Event.ENTER_FRAME, enterFrame);
      stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
      
      addChild(background);
                
      ps = new ParticleSystem(new rParticles, this);       
      ps.descriptor = new Descriptor();

      new ParticleEditor(this, ps);

      label = new Label(this, 0, 0);
		}
        
        
    private var timer:Timer = new Timer(1000);
    private var label:Label;

    private function enterFrame(e:Event):void
    {
        timer.start();
        ps.update();
        ps.descriptor.position = new Vector3D(stage.mouseX, stage.mouseY, 0);
        
        label.text = "UPD (" + ps.particleNum + "): " + (timer.getDelta() * 1000);
    }
            
    private function mouseDown(e:MouseEvent):void
    {
        if (stage.mouseX > 200 && stage.mouseX < 500)
            ps.fire();
    }
    
    public static var background:Sprite = new Sprite();

    private var ps:ParticleSystem;

	}

}